<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>车辆信息登记</title>
    <!-- 引入WeUI CSS -->
    <link rel="stylesheet" href="./weui/weui.min.css">
    <!-- 引入MD5库 -->
    <script src="https://cdn.jsdelivr.net/npm/js-md5@0.8.3/src/md5.min.js"></script>
    <style>
        /* 全局样式 */
        body {
           background-position:center;
           background: linear-gradient( 135deg, #348d5f 0%, #bfbf86 100%);
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
           height: 100vh;
            padding-bottom: 20px;
            overflow: hidden;
        }
        
        .page-container {
            max-width: 600px;
            margin: 0 auto;
            padding: 15px;
        }
        
        /* 头部样式优化 */
        .header {
            text-align: center;
            margin-bottom: 25px;
            padding: 25px 0 15px;
            position: relative;
        }
        
        .header-title {
            font-size: 26px;
            color: #ffffff;
            font-weight: 600;
            margin-bottom: 10px;
            letter-spacing: 1px;
        }
        
        .header-desc {
            font-size: 15px;
            color: #ffffff;
            line-height: 1.5;
        }
        
        /* 表单样式优化 */
        .weui-form {
            background-color: rgba(255,255,255,0.97);
            border-radius: 16px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
            overflow: hidden;
            transition: transform 0.3s ease;
        }
        
        .weui-form:hover {
            transform: translateY(-3px);
        }
        
        .weui-cells {
            margin-top: 0;
        }
        
        .weui-cell {
            padding: 18px 0;
            transition: background-color 0.2s;
        }
        
        .weui-cell:active {
            background-color: rgba(7, 193, 96, 0.05);
        }
        
        .weui-label {
            font-size: 17px;
            color: #333;
            width: 80px;
            font-weight: 500;
        }
        
        .weui-input {
            font-size: 16px;
            color: #333;
            padding: 10px 0;
            transition: border-color 0.3s;
            border-bottom: 1px solid #e5e5e5;
        }
        
        .weui-input:focus {
            border-bottom: 2px solid #07C160;
            padding-bottom: 9px; /* 保持总高度不变 */
        }
        
        .input-container {
            display: flex;
            align-items: center;
            width: 100%;
        }
        
        .weui-cell__bd {
            flex: 1;
        }
        
        /* 图标样式优化 */
        .icon-container {
            display: flex;
            align-items: center;
            margin-left: 10px;
        }
        
        .valid-icon {
            color: #07C160;
            font-size: 18px;
            display: none;
        }
        
        .invalid-icon {
            color: #f43530;
            font-size: 18px;
            display: none;
        }
        
        .weui-cells{
            background-color: transparent;
        }
        
        /* 错误提示样式 */
        .weui-cells__tips {
            font-size: 14px;
            color: #f43530!important;
            margin-top: 6px;
            padding-left: 80px;
            display: none;
            animation: fadeIn 0.3s;
        }
        
        /* 提交按钮区域 */
        .weui-form__opr-area {
            margin: 35px 0 25px;
        }
       
        .weui-form__opr-area:last-child{
            margin-bottom: 25px;
        }
        
        .weui-btn_primary {
            background: linear-gradient(312deg, #47cb87 0%, #bfbf86);
            border-radius: 10px;
            height: 50px;
            font-size: 18px;
            font-weight: 500;
            box-shadow: 0 4px 10px rgba(7, 193, 96, 0.3);
            transition: all 0.3s;
        }
        
        .weui-btn_primary:not(.weui-btn_disabled):active {
            transform: translateY(2px);
            box-shadow: 0 2px 5px rgba(7, 193, 96, 0.3);
        }
        
        .weui-btn_disabled {
            background: #E6E6E6;
            color: #999;
            box-shadow: none;
        }
        
        /* 手机号显示样式 */
        .phone-display {
            font-size: 16px;
            color: #333;
            padding: 10px 0;
            border-bottom: 1px solid #e5e5e5;
        }
        
        .phone-value {
            color: #07C160;
            font-weight: 500;
        }
        
        /* 必填标识 */
        .required::after {
            content: '*';
            color: #f43530;
            margin-left: 2px;
        }
        
        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            15%, 45%, 75% { transform: translateX(-5px); }
            30%, 60%, 90% { transform: translateX(5px); }
        }
        
        .shake {
            animation: shake 0.6s;
        }
        
        /* 响应式调整 */
        @media (max-width: 375px) {
            .weui-label {
                width: 70px;
            }
            
            .weui-cells__tips {
                padding-left: 70px;
            }
            
            .header-title {
                font-size: 22px;
            }
        }
        
        /* 表单组间距 */
        .weui-cells__group {
            margin-bottom: 10px;
        }
        
        /* 输入框placeholder样式 */
        .weui-input::placeholder {
            color: #bbb;
            font-size: 15px;
        }
        
        /* 底部信息 */
        .footer {
            text-align: center;
            margin-top: 25px;
            font-size: 13px;
            color: #999;
        }
        
        /* 状态提示 */
        .status-info {
            text-align: center;
            margin: 15px 0;
            padding: 10px;
            background-color:rgb(218 240 255) !important;
            border-radius: 8px;
            color: #1890ff;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="page-container">
        <div class="header">
            <h1 class="header-title">车辆信息登记✏️</h1>
            <p class="header-desc">请填写真实信息完成车辆登记</p>
        </div>
        
        <div id="statusInfo" class="status-info" style="display: none;"></div>
        
        <div class="weui-form">
            <div class="weui-cells__group weui-cells__group_form">
                <!-- 姓名输入 -->
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd">
                            <label class="weui-label required">姓名</label>
                        </div>
                        <div class="weui-cell__bd">
                            <div class="input-container">
                                <input class="weui-input" id="name" type="text" placeholder="请输入您的真实姓名">
                                <div class="icon-container">
                                    <span class="valid-icon" id="nameValid">✓</span>
                                    <span class="invalid-icon" id="nameInvalid">✗</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="weui-cells__tips" id="nameError">请输入2-10个中文字符</div>
                
                <!-- 手机号输入/显示 -->
                <div class="weui-cells weui-cells_form" id="phoneInputSection">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd">
                            <label class="weui-label required">手机号</label>
                        </div>
                        <div class="weui-cell__bd">
                            <div class="input-container">
                                <input class="weui-input" id="phone" type="tel" placeholder="请输入11位手机号" maxlength="11">
                                <div class="icon-container">
                                    <span class="valid-icon" id="phoneValid">✓</span>
                                    <span class="invalid-icon" id="phoneInvalid">✗</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 车牌号输入 -->
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd">
                            <label class="weui-label required">车牌号</label>
                        </div>
                        <div class="weui-cell__bd">
                            <div class="input-container">
                                <input class="weui-input" id="plate" type="text" placeholder="京A12345/京A12345挂">
                                <div class="icon-container">
                                    <span class="valid-icon" id="plateValid">✓</span>
                                    <span class="invalid-icon" id="plateInvalid">✗</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="weui-cells__tips" id="plateError">请输入有效的车牌号，如:京A12345/京A12345挂</div>

                <!-- 邀请码 -->
                <div class="weui-cells weui-cells_form" id="inviteCodeSection">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd">
                            <label class="weui-label required">邀请码</label>
                        </div>
                        <div class="weui-cell__bd">
                            <div class="input-container">
                                <input class="weui-input" id="inviteCode" type="text" placeholder="请输入邀请码">
                                <div class="icon-container">
                                    <span class="valid-icon" id="inviteCodeValid">✓</span>
                                    <span class="invalid-icon" id="inviteCodeInvalid">✗</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="weui-cells__tips" id="inviteCodeError">邀请码不能为空</div>

                <!-- 手机号显示区域 -->
                <div class="weui-cells weui-cells_form" id="phoneDisplaySection" style="display: none;">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd">
                            <label class="weui-label required">手机号</label>
                        </div>
                        <div class="weui-cell__bd">
                            <div class="phone-display">
                                <span class="phone-value" id="phoneDisplay"></span>
                                <span style="color: #999; margin-left: 10px;">(已绑定)</span>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="weui-cells__tips" id="phoneError">请输入有效的11位手机号</div>
            </div>
            
            <div class="weui-form__opr-area">
                <button type="button" class="weui-btn weui-btn_primary" id="submitBtn">提交登记</button>
            </div>
        </div>
    </div>

    <!-- 引入WeUI JS -->
    <script src="./weui/axios.min.js"></script>
    <script src="./weui/weui.min.js"></script>
    <script src="./axios.js"></script>
    <script src="./api.js"></script>
    <script>
        // 获取DOM元素
        const nameInput = document.getElementById('name');
        const phoneInput = document.getElementById('phone');
        const plateInput = document.getElementById('plate');
        const inviteInput = document.getElementById('inviteCode');
        const submitBtn = document.getElementById('submitBtn');
        const statusInfo = document.getElementById('statusInfo');
        const phoneInputSection = document.getElementById('phoneInputSection');
        const phoneDisplaySection = document.getElementById('phoneDisplaySection');
        const phoneDisplay = document.getElementById('phoneDisplay');
        const inviteCodeSection = document.getElementById('inviteCodeSection');

        // 验证状态
        let isNameValid = false;
        let isPhoneValid = false;
        let isPlateValid = false;
        let isInviteCodeValid = false;
        
        // 当前车辆信息ID（用于修改）
        let currentCarId = null;
        let isEditMode = false; // 是否为编辑模式
        
        // 页面加载时获取车辆信息
        document.addEventListener('DOMContentLoaded', async function() {
             try {
                // 检查本地是否有手机号
                const localPhone = localStorage.getItem('phone');
                
                if (localPhone) {
                    // 有本地手机号，显示手机号而不是输入框
                    showPhoneDisplay(localPhone);
                    isPhoneValid = true; // 本地手机号视为已验证
                } else {
                    // 没有本地手机号，显示输入框
                    showPhoneInput();
                }
                
                if(localStorage.getItem('wechat_openid')){
                    loadCarInfo();
                }
                    
            } catch (error) {
                console.error('页面初始化失败:', error);
                document.getElementById('loading').innerHTML = '加载失败，请刷新页面';
            }
        });
        
        // 显示手机号输入框
        function showPhoneInput() {
            phoneInputSection.style.display = 'block';
            phoneDisplaySection.style.display = 'none';
            isPhoneValid = false;
        }
        
        // 显示手机号显示区域
        function showPhoneDisplay(phone) {
            phoneInputSection.style.display = 'none';
            phoneDisplaySection.style.display = 'block';
            phoneDisplay.textContent = phone;
            isPhoneValid = true;
            updateSubmitButton();
        }
        
        // 显示或隐藏邀请码输入框
        function toggleInviteCodeSection(show) {
            if (show) {
                inviteCodeSection.style.display = 'block';
                isInviteCodeValid = validateInviteCode(inviteInput.value.trim());
            } else {
                inviteCodeSection.style.display = 'none';
                isInviteCodeValid = true; // 编辑模式下邀请码视为有效
            }
            updateSubmitButton();
        }
        
        // 加载车辆信息
        async function loadCarInfo() {
            try {
                const loading = weui.loading('加载中...');
                const phone = localStorage.getItem('phone');
                
                if (phone) {
                    // 调用获取车辆信息接口
                    const response = await getCarListfind({ mobile: phone });
                    
                    loading.hide();
                    
                    if (response.code === 200 && response.data ) {
                        // 有已登记的车辆信息，进入编辑模式
                        const carInfo = response.data;
                        
                        // 填充表单数据
                        nameInput.value = carInfo.username || '';
                        plateInput.value = carInfo.number_plate || '';
                        
                        // 保存当前车辆ID用于修改
                        currentCarId = carInfo.id;
                        isEditMode = true;
                        
                        // 编辑模式下隐藏邀请码
                        toggleInviteCodeSection(false);
                        
                        // 更新验证状态
                        validateAllFields();
                        
                        // 显示状态提示
                        statusInfo.textContent = '已加载您登记的车辆信息，可进行修改';
                        statusInfo.style.display = 'block';
                        statusInfo.style.backgroundColor = '#f0f9ff';
                        statusInfo.style.color = '#1890ff';
                        
                        // 更新按钮文字
                        submitBtn.textContent = '更新信息';
                        
                    } else {
                        // 没有车辆信息，显示新增提示和邀请码
                        statusInfo.textContent = '您尚未登记车辆信息，请填写以下信息';
                        statusInfo.style.display = 'block';
                        statusInfo.style.backgroundColor = '#fff7e6';
                        statusInfo.style.color = '#fa8c16';
                        
                        // 新增模式下显示邀请码
                        toggleInviteCodeSection(true);
                        
                        // 初始化隐藏所有错误提示和图标
                        document.querySelectorAll('.weui-cells__tips').forEach(el => el.style.display = 'none');
                        document.querySelectorAll('.valid-icon, .invalid-icon').forEach(el => el.style.display = 'none');
                    }
                }
                
            } catch (error) {
                console.error('加载车辆信息失败:', error);
                weui.toast('加载失败，请重试', {
                    className: 'weui-toast_warn',
                    duration: 2000
                });
            }
        }
        
        // 验证所有字段
        function validateAllFields() {
            const name = nameInput.value.trim();
            const plate = plateInput.value.trim();
            const inviteCode = inviteInput.value.trim();
            
            isNameValid = validateName(name);
            isPlateValid = validatePlate(plate);
            
            // 只有在新增模式下才验证邀请码
            if (!isEditMode) {
                isInviteCodeValid = validateInviteCode(inviteCode);
            }
            
            // 更新图标显示
            updateValidationIcons();
            updateSubmitButton();
        }
        
        // 更新验证图标
        function updateValidationIcons() {
            const name = nameInput.value.trim();
            const plate = plateInput.value.trim();
            const inviteCode = inviteInput.value.trim();
            
            // 姓名图标
            if (name.length > 0) {
                document.getElementById('nameValid').style.display = isNameValid ? 'inline' : 'none';
                document.getElementById('nameInvalid').style.display = isNameValid ? 'none' : 'inline';
                document.getElementById('nameError').style.display = isNameValid ? 'none' : 'block';
            }
            
            // 车牌号图标
            if (plate.length > 0) {
                document.getElementById('plateValid').style.display = isPlateValid ? 'inline' : 'none';
                document.getElementById('plateInvalid').style.display = isPlateValid ? 'none' : 'inline';
                document.getElementById('plateError').style.display = isPlateValid ? 'none' : 'block';
            }
            
            // 邀请码图标（只在新增模式下显示）
            if (!isEditMode && inviteCode.length > 0) {
                document.getElementById('inviteCodeValid').style.display = isInviteCodeValid ? 'inline' : 'none';
                document.getElementById('inviteCodeInvalid').style.display = isInviteCodeValid ? 'none' : 'inline';
                document.getElementById('inviteCodeError').style.display = isInviteCodeValid ? 'none' : 'block';
            }
        }
        
        // 姓名验证（2-10个中文字符）
        function validateName(name) {
            if (!name) {
                return false;
            }
            return /^[\u4e00-\u9fa5]{2,10}$/.test(name);
        }
        
        // 手机号验证（11位数字，1开头）
        function validatePhone(phone) {
            if (!phone) {
                return false;
            }
            return /^1[3-9]\d{9}$/.test(phone);
        }
        
        // 车牌号验证
        function validatePlate(plate) {
            if (!plate) {
                return false;
            }
            return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1}$/.test(plate);
        }
        
        // 邀请码验证（不能为空）
        function validateInviteCode(code) {
            return code.trim().length > 0;
        }
        
        // 更新提交按钮状态
        function updateSubmitButton() {
            // 编辑模式下不需要验证邀请码
            if (isEditMode) {
                submitBtn.disabled = !(isNameValid && isPhoneValid && isPlateValid);
            } else {
                submitBtn.disabled = !(isNameValid && isPhoneValid && isPlateValid && isInviteCodeValid);
            }
        }
        
        // 显示验证结果
        function showValidationResult(input, isValid, validIcon, invalidIcon, errorMsg, shouldShake = false) {
            if (input.value.trim().length > 0) {
                if (isValid) {
                    validIcon.style.display = 'inline';
                    invalidIcon.style.display = 'none';
                    errorMsg.style.display = 'none';
                } else {
                    validIcon.style.display = 'none';
                    invalidIcon.style.display = 'inline';
                    errorMsg.style.display = 'block';
                    
                    if (shouldShake) {
                        input.parentElement.parentElement.classList.add('shake');
                        setTimeout(() => {
                            input.parentElement.parentElement.classList.remove('shake');
                        }, 600);
                    }
                }
            } else {
                validIcon.style.display = 'none';
                invalidIcon.style.display = 'none';
                errorMsg.style.display = 'none';
            }
            
            updateSubmitButton();
        }
        
        // 姓名输入验证
        nameInput.addEventListener('input', function() {
            const name = this.value.trim();
            isNameValid = validateName(name);
            
            showValidationResult(
                this, 
                isNameValid, 
                document.getElementById('nameValid'),
                document.getElementById('nameInvalid'),
                document.getElementById('nameError'),
                false
            );
        });
        
        nameInput.addEventListener('blur', function() {
            const name = this.value.trim();
            isNameValid = validateName(name);
            
            showValidationResult(
                this, 
                isNameValid, 
                document.getElementById('nameValid'),
                document.getElementById('nameInvalid'),
                document.getElementById('nameError'),
                !isNameValid && name.length > 0
            );
        });
        
        // 手机号输入验证
        phoneInput.addEventListener('input', function() {
            const phone = this.value.trim();
            isPhoneValid = validatePhone(phone);
            
            showValidationResult(
                this, 
                isPhoneValid, 
                document.getElementById('phoneValid'),
                document.getElementById('phoneInvalid'),
                document.getElementById('phoneError'),
                false
            );
        });
        
        phoneInput.addEventListener('blur', function() {
            const phone = this.value.trim();
            isPhoneValid = validatePhone(phone);
            
            showValidationResult(
                this, 
                isPhoneValid, 
                document.getElementById('phoneValid'),
                document.getElementById('phoneInvalid'),
                document.getElementById('phoneError'),
                !isPhoneValid && phone.length > 0
            );
        });
        
        // 车牌号输入验证
        plateInput.addEventListener('input', function() {
            const plate = this.value.trim();
            isPlateValid = validatePlate(plate);
            
            showValidationResult(
                this, 
                isPlateValid, 
                document.getElementById('plateValid'),
                document.getElementById('plateInvalid'),
                document.getElementById('plateError'),
                false
            );
        });
        
        plateInput.addEventListener('blur', function() {
            const plate = this.value.trim();
            isPlateValid = validatePlate(plate);
            
            showValidationResult(
                this, 
                isPlateValid, 
                document.getElementById('plateValid'),
                document.getElementById('plateInvalid'),
                document.getElementById('plateError'),
                !isPlateValid && plate.length > 0
            );
        });
        
        // 邀请码输入验证（只在新增模式下有效）
        inviteInput.addEventListener('input', function() {
            if (!isEditMode) {
                const code = this.value.trim();
                isInviteCodeValid = validateInviteCode(code);
                
                showValidationResult(
                    this, 
                    isInviteCodeValid, 
                    document.getElementById('inviteCodeValid'),
                    document.getElementById('inviteCodeInvalid'),
                    document.getElementById('inviteCodeError'),
                    false
                );
            }
        });
        
        inviteInput.addEventListener('blur', function() {
            if (!isEditMode) {
                const code = this.value.trim();
                isInviteCodeValid = validateInviteCode(code);
                
                showValidationResult(
                    this, 
                    isInviteCodeValid, 
                    document.getElementById('inviteCodeValid'),
                    document.getElementById('inviteCodeInvalid'),
                    document.getElementById('inviteCodeError'),
                    !isInviteCodeValid && code.length > 0
                );
            }
        });
        
        // 提交按钮点击事件
        submitBtn.addEventListener('click', function() {
            // 获取输入值
            const name = nameInput.value;
            const phone = localStorage.getItem('phone') || phoneInput.value;
            const plate = plateInput.value;
            const inviteCode = inviteInput.value;
            
            // 验证所有字段
            isNameValid = validateName(name);
            isPlateValid = validatePlate(plate);
            
            // 只有在新增模式下才验证邀请码
            if (!isEditMode) {
                isInviteCodeValid = validateInviteCode(inviteCode);
            }
            
            // 重置所有错误提示和图标
            document.querySelectorAll('.weui-cells__tips').forEach(el => el.style.display = 'none');
            document.querySelectorAll('.valid-icon, .invalid-icon').forEach(el => el.style.display = 'none');
            document.querySelectorAll('.shake').forEach(el => el.classList.remove('shake'));
            
            // 检查并显示所有字段的错误状态
            let hasError = false;
            let firstErrorElement = null;
            
            // 姓名验证
            if (!isNameValid) {
                document.getElementById('nameError').style.display = 'block';
                document.getElementById('nameInvalid').style.display = 'inline';
                nameInput.parentElement.parentElement.classList.add('shake');
                hasError = true;
                if (!firstErrorElement) firstErrorElement = document.getElementById('nameError');
            }
            
            // 手机号验证
            if (phoneInputSection.style.display !== 'none' && !isPhoneValid) {
                document.getElementById('phoneError').style.display = 'block';
                document.getElementById('phoneInvalid').style.display = 'inline';
                phoneInput.parentElement.parentElement.classList.add('shake');
                hasError = true;
                if (!firstErrorElement) firstErrorElement = document.getElementById('phoneError');
            }
            
            // 车牌号验证
            if (!isPlateValid) {
                document.getElementById('plateError').style.display = 'block';
                document.getElementById('plateInvalid').style.display = 'inline';
                plateInput.parentElement.parentElement.classList.add('shake');
                hasError = true;
                if (!firstErrorElement) firstErrorElement = document.getElementById('plateError');
            }
            
            // 邀请码验证（只在新增模式下验证）
            if (!isEditMode && !isInviteCodeValid) {
                document.getElementById('inviteCodeError').style.display = 'block';
                document.getElementById('inviteCodeInvalid').style.display = 'inline';
                inviteInput.parentElement.parentElement.classList.add('shake');
                hasError = true;
                if (!firstErrorElement) firstErrorElement = document.getElementById('inviteCodeError');
            }
            
            if (hasError) {
                if (firstErrorElement) {
                    firstErrorElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
                }
     
                setTimeout(() => {
                    document.querySelectorAll('.shake').forEach(el => {
                        el.classList.remove('shake');
                    });
                }, 600);
                
                return;
            }
            
            // 所有验证通过，提交表单
            submitCarInfo(name, phone, plate, inviteCode);
        });
        
        // 提交车辆信息
        async function submitCarInfo(name, phone, plate, inviteCode) {
            const loading = weui.loading('提交中...');
            
            try {
                // 构建提交数据
                const submitData = {
                    username: name,
                    mobile: phone,
                    number_plate: plate
                };
                
                // 只有在新增模式下才添加邀请码
                if (!isEditMode) {
                    // 将邀请码转换为MD5格式
                    const codeMD5 = md5(inviteCode);
                    submitData.code = codeMD5;
                }
                
                // 如果有ID，添加到数据中（用于修改）
                if (currentCarId) {
                    submitData.id = currentCarId;
                }
                
                // 调用接口
                const response = await carLogin(submitData);
             
                loading.hide();
                
                if (response.code === 200) {
                    // 保存手机号到本地
                    if (!localStorage.getItem('phone')) {
                        localStorage.setItem('phone', phone);
                        showPhoneDisplay(phone);
                    }
                    
                    localStorage.setItem('wechat_openid', response.data)
                    
                    weui.toast(currentCarId ? '信息更新成功' : '登记成功', {
                        className: 'weui-toast_success',
                        duration: 2000
                    });
                    
                    statusInfo.textContent = currentCarId ? '信息已更新' : '登记成功';
                    statusInfo.style.display = 'block';
                    statusInfo.style.backgroundColor = '#f6ffed';
                    statusInfo.style.color = '#52c41a';
                    
                    submitBtn.textContent = '更新信息';
                    
                    if (response.data && response.data.id) {
                        currentCarId = response.data.id;
                    }
                    console.log(response,'response');
                    
                    window.location.href = '/startWrite.html';
                    
                } else {
                    throw new Error(response.message || '提交失败');
                }
                
            } catch (error) {
                loading.hide();
                console.error('提交失败:', error);
                weui.toast('提交失败，请重试', {
                    className: 'weui-toast_warn',
                    duration: 2000
                });
            }
        }
    </script>
</body>
</html>